#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

#include "ringBuffer.h"


int main()
{
    RING_BUFFER_t *ring = create_ring_buffer(32);
    if(NULL == ring)
    {
        printf("create ring buffer error!\n");
        exit(-1);
    }
    char buff[32] = {0};
    int write_len = ring->write(ring, (uint8_t *)"hello ringbuffer", strlen("hello ringbuffer"));
    if(write_len <= 0)
        printf("[warn] write error!\n");
    
    printf("write len:%d\n", write_len);

    int read_len = ring->read(ring, (uint8_t *)buff, sizeof(buff));
    if(read_len != write_len ||strcmp(buff, "hello ringbuffer"))
        printf("write or read error\n");
    
    printf("read len:%d, buff:%s\n", read_len, buff);

    uint8_t w = 8, r = 0;
    ring->write_byte(ring, w);

    ring->read(ring, &r, 1);
    if(r != w)
        printf("write byte error!\n");

    ring->restore(ring, &r, 1);
    ring->read(ring, &r, 1);
    if(r != w)
        printf("restore error!\n");
    
    ring->destory(&ring);
    return 0;
}

